﻿/* 
 * FreelanceClientDesign.cs
 * 
 * Author - Ankit Gupta and Gaurav Aggarwal
 * 
 * This file handles component design of Freelance Client tab.
 * 
 */

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using Microsoft.Win32;
using System.Windows.Forms;
using System.Text;

partial class FreelanceClientControl
{
    public Label enableFreelanceLabel = new Label();
    public Label nameLabel = new Label();
    public Label targetLabel = new Label();
    public Label symbolicLinkLabel = new Label();
    public Label readOnlyMountPointLabel = new Label();
    public Label readWriteMountPointLabel = new Label();
    public Button addModifyButton = new Button();
    public Button removeButton = new Button();
    public Button applyButton = new Button();
    public Button cancelButton = new Button();
    public RadioButton symbolicLinkRadioButton = new RadioButton();
    public RadioButton readOnlyMountPointRadioButton = new RadioButton();
    public RadioButton readWriteMountPointRadioButton = new RadioButton();
    public TextBox nameTextBox = new TextBox();
    public TextBox targetTextBox = new TextBox();
    public CheckBox enableFreelanceCheckBox = new CheckBox();
    public DataGridView datagrid = new DataGridView();
    public DataGridViewTextBoxColumn Column1 = new DataGridViewTextBoxColumn();
    public DataGridViewTextBoxColumn Column2 = new DataGridViewTextBoxColumn();
    public DataGridViewTextBoxColumn Column3 = new DataGridViewTextBoxColumn();

    RegistryKey serviceParameters = Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\Services\\TransarcAFSDaemon\\Parameters", true);
    RegistryKey symlinks = Registry.LocalMachine.OpenSubKey("SOFTWARE\\OpenAFS\\Client\\Freelance\\Symlinks", true);
    RegistryKey mountpoints = Registry.LocalMachine.OpenSubKey("SOFTWARE\\OpenAFS\\Client\\Freelance", true);
    Array symarr, mountarr;
    int symcount, mountcount;

    public FreelanceClientControl()
    {

        if (symlinks != null)
        {
            symarr = symlinks.GetValueNames();
            symcount = symlinks.ValueCount;
        }

        if (mountpoints != null)
        {
            mountarr = mountpoints.GetValueNames();
            mountcount = mountpoints.ValueCount;
        }

        // Enable/Disable Freelance Client
        enableFreelanceCheckBox.Location = new System.Drawing.Point(20, 10);
        enableFreelanceCheckBox.Name = "enableFreelanceCheckBox";
        enableFreelanceCheckBox.Size = new System.Drawing.Size(15, 20);
        enableFreelanceCheckBox.Checked = Convert.ToBoolean((int)serviceParameters.GetValue("FreelanceClient", 0));

        enableFreelanceLabel.Location = new System.Drawing.Point(40, 10);
        enableFreelanceLabel.Name = "enableFreelanceLabel";
        enableFreelanceLabel.Size = new System.Drawing.Size(200, 30);
        enableFreelanceLabel.Text = "Enable Freelance Client";

        datagrid.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
        datagrid.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { Column1, Column2, Column3 });
        for (int i = 0; i < mountcount; i++)
        {
            if(mountpoints.GetValue(mountarr.GetValue(i).ToString()).ToString()[0]=='.')
            {
                datagrid.Rows.Add(mountarr.GetValue(i).ToString(), "Mount Point(RW)", mountpoints.GetValue(mountarr.GetValue(i).ToString()).ToString());
            }
            else 
            {
                datagrid.Rows.Add(mountarr.GetValue(i).ToString(), "Mount Point(RO)", mountpoints.GetValue(mountarr.GetValue(i).ToString()).ToString());
            }
        }
        for (int i = 0; i < symcount; i++)
        {
            datagrid.Rows.Add(symarr.GetValue(i).ToString(), "Symbolic Links", symlinks.GetValue(symarr.GetValue(i).ToString()).ToString());
        }
        datagrid.Location = new System.Drawing.Point(20, 50);
        datagrid.RowHeadersVisible = false;
        datagrid.BackgroundColor = Color.White;
        datagrid.ReadOnly = true;
        datagrid.Name = "datagrid";
        datagrid.Size = new System.Drawing.Size(530, 200);

        Column1.HeaderText = "Name";
        Column1.Name = "Column1";
        Column1.Width = 178;

        Column2.HeaderText = "Type";
        Column2.Name = "Column2";
        Column2.Width = 178;

        Column3.HeaderText = "Target";
        Column3.Name = "Column3";
        Column3.Width = 171;

        // Name of Freelance object
        nameLabel.Location = new System.Drawing.Point(20, 280);
        nameLabel.Name = "nameLabel";
        nameLabel.Size = new System.Drawing.Size(80, 30);
        nameLabel.Text = "Name";

        nameTextBox.Location = new System.Drawing.Point(100, 280);
        nameTextBox.Name = "nameTextBox";
        nameTextBox.Size = new System.Drawing.Size(200, 40);

        // Target of Freelance Object
        targetLabel.Location = new System.Drawing.Point(20, 320);
        targetLabel.Name = "targetLabel";
        targetLabel.Size = new System.Drawing.Size(80, 30);
        targetLabel.Text = "Target";

        targetTextBox.Location = new System.Drawing.Point(100, 320);
        targetTextBox.Name = "targetTextBox";
        targetTextBox.Size = new System.Drawing.Size(200, 40);

        // Symbolic Link
        symbolicLinkRadioButton.Location = new System.Drawing.Point(100, 360);
        symbolicLinkRadioButton.Name = "symbolicLinkRadioButton";
        symbolicLinkRadioButton.Size = new System.Drawing.Size(20, 20);
        symbolicLinkRadioButton.Checked = true;

        symbolicLinkLabel.Location = new System.Drawing.Point(120, 363);
        symbolicLinkLabel.Name = "symbolicLinkLabel";
        symbolicLinkLabel.Size = new System.Drawing.Size(150, 30);
        symbolicLinkLabel.Text = "Symbolic link";

        // Mount Point (Read Only or Read/Write)
        readOnlyMountPointRadioButton.Location = new System.Drawing.Point(100, 390);
        readOnlyMountPointRadioButton.Name = "readOnlyMountPointRadioButton";
        readOnlyMountPointRadioButton.Size = new System.Drawing.Size(20, 20);

        readOnlyMountPointLabel.Location = new System.Drawing.Point(120, 393);
        readOnlyMountPointLabel.Name = "readOnlyMountPointLabel";
        readOnlyMountPointLabel.Size = new System.Drawing.Size(150, 30);
        readOnlyMountPointLabel.Text = "Read-only mount point";

        readWriteMountPointRadioButton.Location = new System.Drawing.Point(100, 420);
        readWriteMountPointRadioButton.Name = "readWriteMountPointRadioButton";
        readWriteMountPointRadioButton.Size = new System.Drawing.Size(20, 20);

        readWriteMountPointLabel.Location = new System.Drawing.Point(120, 423);
        readWriteMountPointLabel.Name = "readWriteMountPointLabel";
        readWriteMountPointLabel.Size = new System.Drawing.Size(150, 30);
        readWriteMountPointLabel.Text = "Read-write mount point";

        // Add/Modify button
        addModifyButton.Location = new System.Drawing.Point(300, 420);
        addModifyButton.Name = "addModifyButton";
        addModifyButton.Size = new System.Drawing.Size(100, 23);
        addModifyButton.Text = "Add/Modify";
        addModifyButton.Click += new System.EventHandler(buttonAddModify_Click);

        // Remove button
        removeButton.Location = new System.Drawing.Point(420, 420);
        removeButton.Name = "removeButton";
        removeButton.Size = new System.Drawing.Size(100, 23);
        removeButton.Text = "Remove";
        removeButton.Click += new System.EventHandler(buttonRemove_Click);

        applyButton.Location = new System.Drawing.Point(20, 460);
        applyButton.Name = "applyButton";
        applyButton.Size = new System.Drawing.Size(100, 23);
        applyButton.Text = "Apply";
        applyButton.Click += new System.EventHandler(applyButton_Click);

        cancelButton.Location = new System.Drawing.Point(140, 460);
        cancelButton.Name = "cancelButton";
        cancelButton.Size = new System.Drawing.Size(100, 23);
        cancelButton.Text = "Cancel";
        cancelButton.Click += new System.EventHandler(cancelButton_Click);
    }
}